<template>
	<view class="orders-section">
		<view class="card" v-for="item in orderList">
			<view style="flex-basis: 25%;">
				<image :src="handlerPicture(item.picture)"></image>
			</view>
			<view class="info_block">
				<view class="name">{{item.house_name}}</view>
				<view class="time">{{handlerTime(item.creation_time)}}</view>
				<!-- <view class="price">金额</view> -->
			</view>
			<view style="flex-basis:20%;">
				<view v-if="item.order_status == 0">
					<button type="primary" @click="pay(item.order_id)">缴费</button>
				</view>
				<view v-if="item.order_status == 1">
					<span>已缴费</span>
				</view>
				<view v-if="item.order_status == 2">
					<view>失效</view>
				</view>
			</view>
		</view>
	</view>

	</view>
</template>
<script>
	import moment from '@/common/moment';
	import listCell from '@/components/oa-list-cell';
	import {
		mapMutations
	} from 'vuex';

	export default {
		components: {
			listCell
		},
		data() {
			return {
				orderList: [],
			};
		},
		async onShow() {
			// 初始化数据
			await this.initData();
		},

		onLoad() {
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.themeColor.color,
				animation: {
					duration: 400,
					timingFunc: 'easeIn'
				}
			})
		},

		methods: {
			// 数据初始化
			async initData() {
				this.$mRed.request({
					url: 'api/order/',
					method: 'get',
				}).then(r => {
					this.orderList = r[1].data.data

				})
			},
			// 统一跳转接口,拦截未登录路由
			navTo(route) {
				this.$mRouter.push({
					route
				});
			},

			handlerPicture(pictureUrl) {
				return pictureUrl != '' && pictureUrl != undefined ?
					this.$mRed.baseURL + pictureUrl :
					this.$mAssetsPath.notFoundImg
			},

			handlerTime(tiem) {
				return moment(tiem).format("YYYY-MM-DD hh:mm:ss")
			},

			pay(houseId) {

				uni.showModal({
					title: '消息',
					content: '确认支付',
					success: r => {
						if (r.confirm) {
							this.$mRed.request({
								url: 'api/order/pay/' + houseId,
								method: 'post'
							}).then(r => {
								let data = r[1].data
								if (data.code == 200) {
									uni.showToast({
										icon: 'success',
										title: data.msg,
									})
									this.initData()
								} else {
									uni.showToast({
										icon: 'error',
										title: data.msg,
									})
								}
							})
						}
					}
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	page {
		background-color: $page-color-base;
	}

	.orders-section {
		padding: 0 30upx 20upx;

		.card {
			margin-top: $spacing-lg;
			padding: 20px 10px;
			background-color: white;
			border-radius: 10upx;
			display: flex;
			justify-content: space-between;

			image {
				width: 200upx;
				height: 150upx;
				// border: 1px solid black;
			}

			.info_block {
				flex-basis: 55%;
				padding: 0 $spacing-base;
			}
		}

		button {
			position: relative;
			top: 70upx;
		}

		.price {
			color: red;
			font-size: $font-lg;
			float: right;
		}

		.time {
			color: grey;
			font-size: $font-sm;
		}

		.name {
			// font-weight: bold;
		}

		.text {
			display: block;
			color: grey;
			width: 15%;
			float: left;
			// font-size: $font-sm;
		}
	}
</style>
